﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YArchitech.Controls;
using YArchitech.LIB;

namespace YArchitech.Temp
{
	public partial class PipeAttachInfoForm : System.Windows.Forms.Form
	{
		public PipeAttachInfoForm()
		{
			this.InitializeComponent();
			base.Icon = Resource.YArchitechIcon;
			base.CenterToParent();
		}

		public PipeAttachInfoForm(HYPipeStraight duct, bool terminalValueReadonly = false) : this()
		{
			this.m_Pipe = duct;
			this.m_TerminalValueReadonly = terminalValueReadonly;
			if (this.m_Pipe != null && this.m_Pipe.AttachObjects != null)
			{
				foreach (HYPipeline.AttachObject ao in this.m_Pipe.AttachObjects)
				{
					DataGridViewRow dataGridViewRow = this.CreateRow(ao);
					this.hyGridView1.Rows.Add(dataGridViewRow);
				}
			}
		}

		private DataGridViewRow CreateRow(HYPipeline.AttachObject ao)
		{
			DataGridViewRow dataGridViewRow = new DataGridViewRow();
			dataGridViewRow.CreateCells(this.hyGridView1);
			dataGridViewRow.Tag = ao;
			dataGridViewRow.Cells[0].Value = ao.ShowName;
			dataGridViewRow.Cells[1].SetValue(ao.Value, 3);
			return dataGridViewRow;
		}

		private void hyGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
		{
			this.hyInplaceTextBox1.OnHide();
			int rowIndex = e.RowIndex;
			int columnIndex = e.ColumnIndex;
			if (1 != columnIndex || rowIndex < 0)
			{
				return;
			}
			DataGridViewRow dataGridViewRow = this.hyGridView1.Rows[rowIndex];
			HYPipeline.AttachObject attachObject = dataGridViewRow.Tag as HYPipeline.AttachObject;
			if (attachObject == null || (attachObject.IsTerminal && this.m_TerminalValueReadonly))
			{
				return;
			}
			DataGridViewCell cell = dataGridViewRow.Cells[1];
			this.hyInplaceTextBox1.MoveToCell(cell);
		}

		private void hyGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
		{
		}

		private void btnOK_Click(object sender, EventArgs e)
		{
			if (this.m_Pipe == null)
			{
				base.DialogResult = DialogResult.Cancel;
				return;
			}
			foreach (object obj in ((IEnumerable)this.hyGridView1.Rows))
			{
				DataGridViewRow dataGridViewRow = (DataGridViewRow)obj;
				HYPipeline.AttachObject attachObject = dataGridViewRow.Tag as HYPipeline.AttachObject;
				attachObject.Value = dataGridViewRow.Cells[1].GetDoubleValue();
				attachObject.Save();
			}
			double num;
			double num2;
			this.m_Pipe.GetAttachObjectInfo(out num, out num2);
			base.DialogResult = DialogResult.OK;
		}

		private HYPipeStraight m_Pipe;

		private bool m_TerminalValueReadonly;
	}
}
